package com.jwaoo.mobile.view.user;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;

import com.dx.as.UI;
import com.dx.as.listener.IViewInterface;
import com.jwaoo.chat.UserInfo;
import com.jwaoo.chat.activity.P2PMessageActivity;
import com.jwaoo.mobile.ApplicationHelper;
import com.jwaoo.mobile.R;
import com.jwaoo.mobile.forchat.IFroChatMouleImpl;
import com.jwaoo.mobile.view.user.presenter.UserPresenter;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by jwaoo on 2017/12/11.
 */

public class UserActivity extends UI implements IUserView{
    private int uid;
    private ScrollView scrollview;
    private Handler handler = new Handler(){};
    private UserPresenter userPresenter;
    private ImageView img_bg;
    private TextView tv_nickname;
    @Override
    protected void onActivityCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_user);
        uid = getIntent().getIntExtra("id",0);
        scrollview = findViewById(R.id.scrollview);
        tv_nickname = findView(R.id.tv_nickname);
        img_bg = findViewById(R.id.img_bg);
        handler.post(new Runnable() {
            @Override
            public void run() {
                scrollview.fullScroll(View.FOCUS_DOWN);
            }
        });
        userPresenter = new UserPresenter(this,this);
        setToolbar(null);
        userPresenter.getContactInfo(uid);
    }

    public void onViewClick(View view){
        switch (view.getId()){
            case R.id.btn_chat:
                if (ApplicationHelper.isActivityStarted(P2PMessageActivity.class)){
                    finish();
                }else {
                    IFroChatMouleImpl.getInstance().startChatting(uid);
                }
                break;
            case R.id.btn_follow:
                break;
        }
    }

    @Override
    public void getUserInfo(final UserInfo userInfo) {
        if (userInfo != null){
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    ImageLoader.getInstance().displayImage(userInfo.getAvatar(),img_bg);
                    tv_nickname.setText(userInfo.getNickname());
                }
            });

        }
    }
}
